﻿
using SanJ.FreeCare.ValueSets;
using System;
using System.Collections.Generic;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace SanJ.FreeCare.Locations
{
    public class Location : AuditedAggregateRoot<Guid>, IMultiTenant, ISoftDelete
    {
        public string? Spell {  get; set; }
        /// <summary>
        /// 第三方ID
        /// </summary>
        public string ThirdId { get;  set; }

        /// <summary>
        /// Hierarchical Code of this organization unit.
        /// Example: "00001.00042.00005".
        /// This is a unique code for an OrganizationUnit.
        /// It's changeable if OU hierarchy is changed.
        /// </summary>
        public double Code { get;  set; }

        /// <summary>
        /// 是否有效
        /// </summary>
        public string IsVaild { get;  set; }

        /// <summary>
        /// 操作状态，通常用于room、bed，即是否被占用
        /// </summary>
        public string OperationalStatus { get;  set; }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get;  set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get;  set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }

         /// <summary>
        /// 类型
        /// </summary>
        public string Type { get;  set; }

        /// <summary>
        /// 详细地址
        /// </summary>
        public string Addr { get;  set; }

        /// <summary>
        /// 物理类型
        /// </summary>
        public string PhysicalType { get;  set; }

        /// <summary>
        /// 管理机构id
        /// </summary>
        public Guid OrganizationId { get;  set; }

        public Guid? TenantId { get; set; }

        public bool IsDeleted { get; set; }
        /// <summary>
        /// 父节点id
        /// </summary>
        public Guid? ParentId { get; set; }
        public Location()
        {

        }

        public Location(Guid id, Guid? _parentId, double _code, string thirdId, string _name, string _type, string _physicalType, Guid organizationId) : base(id)
        {
            Code = _code;
            this.ThirdId = thirdId;
            Name = _name;
            Type = _type;
            PhysicalType = _physicalType;
            this.OrganizationId = organizationId;

            this.IsVaild = VaildType.Vaild;

            if (_physicalType == LocationPhysicalType.Bed || _physicalType == LocationPhysicalType.Seat)
            {
                this.OperationalStatus = LocationOperationalStatus.Unoccupied;
            }
        }

        public void Update(string _name, string thirdId, Guid organizationId,int sort)
        {
            this.Name = _name;
            this.ThirdId = thirdId;
            this.OrganizationId = organizationId;
            this.Sort= sort;
        }

        public void UpdateName(string _name)
        {
            this.Name = _name;
        }

        public void UnActive()
        {
            this.IsVaild = VaildType.InVaild;
        }

        /// <summary>
        /// 位置占用
        /// </summary>
        public void Occupied()
        {
            this.OperationalStatus = LocationOperationalStatus.Occupied;
        }

        /// <summary>
        /// 解除占用
        /// </summary>
        public void Unoccupied()
        {
            this.OperationalStatus = LocationOperationalStatus.Unoccupied;
        }

        public void SetDisplayOrder(int sort)
        {
            this.Sort = sort;
        }
    }
}